package com.lanmaoly.study.aop;

import com.lanmaoly.study.service.AuthService;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * Created by chao.xia on 2018/1/7 15:02
 */
@Aspect
@Component
public class AuthAspect {

    @Autowired
    private AuthService authService;

    @Pointcut(value = "@annotation(com.lanmaoly.study.annotation.AdminOnly)")
    public void adminOnly() {
        System.out.println("this is point cut");

    }


    @Before("adminOnly()")
    public void auth(){
        System.out.println("this is before");
        String name = "admin";
        authService.auth(name);
    }


}
